#!/bin/bash

PRO_DIR=`dirname $0`
BIN_PATH=/usr/local/bin
USER_HOME_DIR=`eval echo "~$USER"`
DESKFILE=$USER_HOME_DIR/Desktop/StressTool.desktop
PRO_NAME=stresstool.py

echo "Install soft dependency."

for pkg in 'glmark2' 'python3-pip' 'python3-tk'
do
  if ! dpkg -s $pkg &>/dev/null
    then
      apt-get install -y $pkg
    else
      echo $pkg installed.
  fi
done 

sudo pip3 install jetson-stats -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com

sudo cp -v $PRO_DIR/$PRO_NAME $BIN_PATH/$PRO_NAME

cat << EOF >> $DESKFILE 
[Desktop Entry]
Type=Application
Exec=$BIN_PATH/stresstool.py
Name=Stress Tool 
GenericName=A GPU and CPU Stress test tool
Terminal=false
Categories=Launcher;Benchmark;
EOF

chmod +x $DESKFILE
echo "GUI program installed in $USER_HOME_DIR/Desktop"


echo "Done."
